import requests

# 登录信息
username = "wujian@tricheer.com"
password = "111111"

# 构造登录数据
login_data = {
    "account": username,
    "password": password
}

# 构造表格数据请求参数
person_list_req_body = {
    "startTime": "2024-11-01",
    "endTime": "2024-11-25",
    "pageSize": 50,
    "pageNo": 1
}

# 登录URL
login_url = "http://172.16.170.50/personnel/login-pwd.do"

# 表格数据URL
table_url = "http://172.16.170.50/personnel/attendance/day/person-list"

# 构造请求头
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
}

# 登录会话
session = requests.Session()

# 发送登录请求
response = session.post(login_url, data=login_data, headers=headers)

# 检查登录是否成功
if response.status_code!= 200:
    print("登录失败")
    exit()

# 从登录响应中提取Cookie
cookies = response.cookies

response = session.post("http://172.16.170.50/personnel/menu/list.do")

# 发送表格数据请求，同时携带Cookie
response = session.post(table_url, json=person_list_req_body, cookies=cookies)

# 检查响应状态码
if response.status_code!= 200:
    print("请求表格数据失败 ", response.status_code)
    exit()
data = response.json()

my_hour = 0
for value in data['data']['records']:
    #print(value)
    dst =  value['overTimeHoursToDaysOff']
    if dst is not None:
        print(value['attendanceStartTime'], value['attendanceEndTime'], dst)
        my_hour = my_hour + dst
print('overTimeHoursToDaysOff=', my_hour)
